package controllers;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;

import play.Logger;
import play.libs.F.EventStream;
import play.mvc.Http.WebSocketEvent;
import play.mvc.WebSocketController;

public class MyWebSocket extends WebSocketController {

	
    public static EventStream<String> liveStream = new EventStream<String>();

    public static void asyncMessage() throws InterruptedException {
    	int i = 1;
        while (inbound.isOpen()) {
            String message = await(liveStream.nextEvent());
            if (message != null) {
//          	  try {
//        	      Thread.sleep(2000);
//        	  } catch (InterruptedException e) {
//        	      Logger.error(e.getMessage());
//        	  }
          	  	System.out.println(i++);
                outbound.send(message);                
            }
        }
        
    }
    
    public static void disconnect(){
    	outbound.close();
    	MyWebSocket.inbound.close();
    }
}
